﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tasks.Dao;
using Tasks.Common;
using Tasks.Common.Entitys;
using System.Collections;
using Tasks.Common.Enum;
using System.Data;
namespace Tasks.Business
{
    public class BasedataBLL : MyBaseBLL
    {
        DictGroupDao dgDao = new DictGroupDao();
        DictValueDao dvDao = new DictValueDao();

        public BasedataBLL(int ownerID)
            : base(ownerID)
        {

        }

        /// <summary>
        /// 获取指定用户可见的菜单
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public IList<Menu> GetUserMenus(int userID, string appIDs)
        {
            return new MenuDao().FindByUserID(userID, appIDs);
        }

        /// <summary>
        /// 获取所有菜单
        /// </summary>
        /// <returns></returns>
        public IList<Menu> GetAllMenus()
        {

            return new MenuDao().FindAll();
        }

        /// <summary>
        /// 搜索相册的相片
        /// </summary>
        /// <param name="albumID"></param>
        /// <param name="keyID">线路、酒店、门票的ID</param>
        /// <returns></returns>
        public IList<Photo> SearchPhotos(Int32 albumID, int keyID)
        {
            Hashtable condition = new Hashtable();
            condition["AlbumID"] = albumID;
            condition["KeyID"] = keyID;

            return new PhotoDao().Search(condition);
        }


        /// <summary>
        /// 从企业会员中获取业务员
        /// </summary>
        /// <param name="albumID"></param>
        /// <param name="keyID">线路、酒店、门票的ID</param>
        /// <returns></returns>
        public IList<Employee> SearchSalesmanIDEmployee()
        {
            return new EmployeeDao().FindEmployee(this.OwnerID);
        }
        /// <summary>
        /// 保存线路模板
        /// </summary>
        /// <param name="dict"></param>
        /// <returns></returns>
        public ExecuteResult SaveTourCalendarTemplate(DictValue dict)
        {
            dict.DictKey = DictConfig.TOUR_CALENDAR_TEMPLATE;
            return this.CreateDict(dict);
        }

        /// <summary>
        /// 线路行程模板字典
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> SearchTourCalendarTemplates(string searchKey, int pageIndex, int pageSize, out int rowCount)
        {
            Hashtable condition = new Hashtable();
            condition["Content"] = searchKey;
            condition["DictKey"] = DictConfig.TOUR_CALENDAR_TEMPLATE;

            return this.SearchDictByCondition(condition, pageIndex, pageSize, out rowCount);
        }

        /// <summary>
        /// 按字典关键字查找字典值
        /// </summary>
        /// <param name="ht">参数值：Content \DictKey、OwnerID、PageIndex、PageSize、out RowCount</param>
        /// <returns></returns>
        public IList<DictValue> SearchDictByCondition(Hashtable condition, int pageIndex, int pageSize, out int rowCount)
        {
            condition["OwnerID"] = this.OwnerID;
            return dvDao.FindByCondition(condition, pageIndex, pageSize, out rowCount);
        }

        /// <summary>
        /// 获取省份
        /// </summary>
        /// <returns></returns>
        public IList<Citys> GetProvinecs()
        {
            return new CitysDao().FindByParentID(1);
        }

        /// <summary>
        /// 获取城市数据
        /// </summary>
        /// <param name="parentID"></param>
        /// <returns></returns>
        public IList<Citys> GetCitysByParentID(int parentID)
        {
            if (parentID == 0) return new List<Citys>();
            return new CitysDao().FindByParentID(parentID);
        }
        /// <summary>
        /// 获取角色数据
        /// </summary>
        /// <param name="parentID"></param>
        /// <returns></returns>
        public IList<PowerRole> GetRoles()
        {

            return new PowerRoleDao().FindAll(this.OwnerID);
        }
        /// <summary>
        /// 获取城市信息
        /// </summary>
        /// <param name="cityID"></param>
        /// <returns></returns>
        public Citys GetCity(int cityID)
        {
            return new CitysDao().Find(cityID);
        }

        public Citys GetCityName(string cityName)
        {
            return new CitysDao().GetCityName(cityName);
        }

        public IList<DictValue> GetTourCategorys()
        {
            return this.GetDicts(DictConfig.TOUR_CATE);
        }
        /// <summary>
        /// 获取酒店主题
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetHotelTheme()
        {
            return this.GetDicts(DictConfig.HOTELPLAYTHEME);
        }

        /// <summary>
        /// 获取餐厅标准数据
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetDiningStandard()
        {
            return this.GetDicts(DictConfig.DINING_STANDARD_SET);
        }

        /// <summary>
        /// 获取线路主题数据
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetTourTheme()
        {
            return this.GetDicts(DictConfig.Tour_Play_theme);
        }

        /// <summary>
        /// 获取地接费用
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetTeamPlanCharges()
        {
            return this.GetDicts(DictConfig.TOUR_TEAM_PLAN_CHARGES);
        }

        /// <summary>
        /// 获取语言
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetGuidLanguage()
        {
            return this.GetDicts(DictConfig.TOUR_GUIDE_LANGUAGE);
        }
        /// <summary>
        /// 获取购物点类别
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetShopType()
        {

            return this.GetDicts(DictConfig.SHOP_SPACE_TYPE);
        }
        /// <summary>
        /// 获取导游要求
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetTourTeamPlanGuideRequire()
        {
            return this.GetDicts(DictConfig.TOURTEAMPLAN_GUIDE_REQUIRE);
        }
        /// <summary>
        /// 获取导游注意事项
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetTourTeamPlanGuideAttention()
        {
            return this.GetDicts(DictConfig.TOURTEAMPLAN_GUIDE_ATTENTION);
        }
        /// <summary>
        /// 获取企业会员分组数据
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetEnterpriseMemberCategorys()
        {
            return this.GetDicts(DictConfig.ENT_MEMBER_CAT);
        }

        ////会员类别
        public IList<DictValue> Per_Member_Cat()
        {
            return this.GetDicts(DictConfig.PER_MEMBER_CAT);
        }
        ///
        /// 客户来源
        /// 
        public IList<DictValue> Per_Member_Source()
        {
            return this.GetDicts(DictConfig.PER_MEMBER_SOURCE);
        }
        /// <summary>
        /// 获取部门数据
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetDepartments()
        {
            return this.GetDicts(DictConfig.DEPT);
        }
        /// <summary>
        /// 获取景点主题数据
        /// </summary>
        /// <returns></returns>
        public IList<DictValue> GetSceneryTheme()
        {
            return this.GetDicts(DictConfig.Scenery_Play_theme);
        }
        /// <summary>
        /// 字典名称
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public DictGroup GetDictGroupByKey(string key)
        {
            return new DictGroupDao().Find(key);
        }

        /// <summary>
        /// 获取指定字典值
        /// </summary>
        /// <param name="dictID">字典ID</param>
        public DictValue GetDict(int dictID)
        {
            return dvDao.Find(dictID);
        }

        /// <summary>
        /// 获取字典列表
        /// </summary>
        public IList<DictValue> GetDicts(string dictKey)
        {
            IList<DictValue> dicts = new List<DictValue>();
            dicts = dvDao.FindByDictKey(dictKey, this.OwnerID);

            //如果没有基础数据，从管理公司初始一份
            if (this.OwnerID != DictConfig.CompanyID && dicts.Count == 0)
            {
                IList<DictValue> newDicts = dvDao.FindByDictKey(dictKey, DictConfig.CompanyID);
                foreach (DictValue newDict in newDicts)
                {
                    newDict.OwnerID = this.OwnerID;
                    dvDao.Insert(newDict);
                }
                return newDicts;
            }
            return dicts;
        }

        /// <summary>
        /// 获取字典列表
        /// </summary>
        public IList<DictValue> GetDicts(string dictKey, int ownerID)
        {
            IList<DictValue> dicts = new List<DictValue>();
            dicts = dvDao.FindByDictKey(dictKey, ownerID);
            return dicts;
        }
        /// <summary>
        /// 创建字典值
        /// </summary>
        public ExecuteResult CreateDict(DictValue dict)
        {
            dict.OwnerID = this.OwnerID;
            dict.State = 1;
            dvDao.Insert(dict);
            return new ExecuteResult() { ResultNo = 1, Message = "" };
        }

        /// <summary>
        /// 修改字典值
        /// </summary>
        public ExecuteResult ModifyDict(DictValue dict)
        {
            dict.OwnerID = this.OwnerID;
            dvDao.Update(dict);
            return new ExecuteResult() { ResultNo = 1, Message = "" };
        }

        /// <summary>
        /// 删除字典值
        /// </summary>
        /// <param name="dictID"></param>
        /// <returns></returns>
        public ExecuteResult DeleteDict(int dictID)
        {
            return this.SetDictState(dictID, 0);
        }

        /// <summary>
        /// 设置字典状态
        /// </summary>
        public ExecuteResult SetDictState(int dictID, int state)
        {
            dvDao.UpdateState(dictID, state);
            return new ExecuteResult() { ResultNo = 1, Message = "" };
        }

        /// <summary>
        /// 获取字典列表
        /// </summary>
        public IList<Dict> GetDicts()
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// 创建相册
        /// </summary>
        public void CreateAlbum()
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// 修改相册
        /// </summary>
        public void ModifyAlbum()
        {
            throw new System.NotImplementedException();
        }

        public void DeleteAlbum()
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// 添加相片
        /// </summary>
        public ExecuteResult AddPhoto(Photo p)
        {
            new PhotoDao().Insert(p);
            return new ExecuteResult() { Message = "", ResultNo = 1 };
        }

        /// <summary>
        /// 删除相片
        /// </summary>
        public ExecuteResult DeletePhoto(int photoID)
        {
            new PhotoDao().Delete(photoID);
            return new ExecuteResult() { Message = "", ResultNo = 1 };
        }

        public Photo GetPhoto(int photoID)
        {
            return new PhotoDao().Find(photoID);
        }



        public string GetPostion(int provinceID, int cityID, int areaID)
        {
            return new CitysDao().GetPostion(provinceID, cityID, areaID);
        }

      
    }
}
